import { create } from "zustand";
import _ from "lodash";

/**
 * 选中高亮
 */
const useSelectBorder = create<SelectBorderType>((set) => ({
  select: {},
  selectId: "",
  debug: false,
  nodeConfig: {},
  nodeConfigId: "",
  setNodeConfig(id) {
    set((state) => {
      _.forEach(state.nodeConfig, (value, key) => {
        state.nodeConfig[key] = false;
      });
      state.nodeConfig[id] = true;
      return ({ nodeConfig: { ...state.nodeConfig } })
    });
    set(() => ({ nodeConfigId: id }));
  },
  clearNodeConfig() {
    set((state) => {
      _.forEach(state.nodeConfig, (value, key) => {
        state.nodeConfig[key] = false;
      });
      return ({ nodeConfig: { ...state.nodeConfig } })
    });
  },
  setDeBug: (debug: boolean) => {
    set((state) => ({ ...state, debug }));
  },
  setSelectId: (id: string) => {
    set((state) => {
      _.forEach(state.select, (value, key) => {
        state.select[key] = false;
      });
      state.select[id] = true;
      return ({ select: { ...state.select } })
    });
    set(() => ({ selectId: id }));
  }
}));

export default useSelectBorder;

